def list_or_tuple(x):
    return isinstance(x, (list, tuple))

def flatten(sequence, to_expand=list_or_tuple):
    iters = [iter(sequence)]
    while iters:
        for item in iters[-1]:
            if to_expand(item):
                iters.append(iter(item))
                break
            yield item
        else:
            iters.pop()

print list(flatten(['a', 'b', [1, [2, '']]]))